/***************************************************************************
 *   Copyright (C) 2009 by Macedo                                          *
 *   tmacedo29@gmail.com                                                   *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU Library General Public License as       *
 *   published by the Free Software Foundation; either version 2 of the    *
 *   License, or (at your option) any later version.                       *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU Library General Public     *
 *   License along with this program; if not, write to the                 *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 *                                                                         *
 *                                                                         *
 * 19.04.2009  Macedo: 1st Release                                         *
 *                                                                         *
 ***************************************************************************/

#include <Card.h>
#include <QMessageBox>
#include <QApplication>

Card::Card( Suits par_suit, SuitColor par_type, QWidget* parent, Qt::WindowFlags fl ):QWidget(parent,fl)
{
  _CardImage = new QLabel(parent);
  QImage image;
  
  switch (par_suit)
  {
    case Suit_Diamonds:
      {
        Diamonds SuitDiamond(par_type);
        image = SuitDiamond.GetImageCard(-1);
      }
      break;

    case Suit_Spades:
      {
        Spades SuitSpades(par_type);
        image = SuitSpades.GetImageCard(-1);
      }
      break;

    case Suit_Hearts:
      {
        Hearts SuitHearts(par_type);
        image = SuitHearts.GetImageCard(-1);
      }
      break;

    case Suit_Clubs:
      {
        Clubs SuitClubs(par_type);
        image = SuitClubs.GetImageCard(-1);
      }
      break;
  }
  _Suit = par_suit;

  if (!image.isNull()) 
  {    
    _CardImage->setPixmap(QPixmap::fromImage(image));
    _CardImage->resize(0.3 * _CardImage->pixmap()->size());
  }
  else
  {
    QMessageBox::information(this, "Erro", "Erro ao abrir a imagem" );
    qApp->quit();
  }  
  _CardImage->setBackgroundRole(QPalette::Base);
  _CardImage->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
  _CardImage->setScaledContents(true);
  _Value = -1;

  // Drag/Drop part
  setAcceptDrops(true);
}

Card::~Card()
{
  delete _CardImage;
}

int Card::Value(void)
{
  return _Value;
}

void Card::Value(int par_value, SuitColor par_type)
{
  QImage image;
  _Value = par_value;

  switch (_Suit)
  {
    case Suit_Diamonds:
      {
        Diamonds SuitDiamond(par_type);
        image = SuitDiamond.GetImageCard(_Value);
      }
      break;

    case Suit_Spades:
      {
        Spades SuitSpades(par_type);
        image = SuitSpades.GetImageCard(_Value);
      }
      break;

    case Suit_Hearts:
      {
        Hearts SuitHearts(par_type);
        image = SuitHearts.GetImageCard(_Value);
      }
      break;

    case Suit_Clubs:
      {
        Clubs SuitClubs(par_type);
        image = SuitClubs.GetImageCard(_Value);
      }
      break;
  }
  if (!image.isNull()) 
  {    
    _CardImage->setPixmap(QPixmap::fromImage(image));
    _CardImage->resize(0.3 * _CardImage->pixmap()->size());
  }
  else
  {
    QMessageBox::information(this, "Erro", "Erro ao abrir a imagem" );
    qApp->quit();
  }
}
  

  
  
  
  